%%%-------------------------------------------------------------------
%%% File    : iter_list.erl
%%% Author  :  <vjache>
%%% Description : 
%%%
%%% Created : 12 Aug 2009 by  <vjache>
%%%-------------------------------------------------------------------
-module(iter_list).

%%--------------------------------------------------------------------
%% Include files
%%--------------------------------------------------------------------
-include_lib("eunit/include/eunit.hrl").

-include("../include/iter.hrl").

%% API
-export([new/1,next/1,open/1,close/1]).

%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: 
%% Description:
%%--------------------------------------------------------------------
new(List) when is_list(List)->
	#iter{param=List,impl=?MODULE}.
open(List)-> 
	List.
next([H|Tail]) -> 
	{Tail,H};
next([]) -> 
	{[],?EOF}.
close(_State) -> 
	ok.

%%====================================================================
%% eunit test functions
%%====================================================================

basic_test() ->
	TestData=[1,2,3],
	ISt0=iter:open(new(TestData)),
	{ISt1,1}=iter:next(ISt0),
	{ISt2,2}=iter:next(ISt1),
	{ISt3,3}=iter:next(ISt2),
	{ISt4,?EOF}=iter:next(ISt3),
	iter:close(ISt4).

to_list_test() ->
	TestData=[1,2,3],
	ISt0=iter:open(new(TestData)),
	TestData=iter:to_list(ISt0).

to_list1_test() ->
	TestData=[1,2,3],
	I=new(TestData),
	TestData=iter:to_list(I).
